const sweetAlert = ( message = "Internal Server Error!", status = "error", attr = {}, callback ) => { let config = { html: message, icon: status, confirmButtonText: "Ya, lanjut!", cancelButtonText: "Tidak, batal", buttonsStyling: !1, customClass: { confirmButton: "btn fw-bold btn-primary", cancelButton: "btn fw-bold btn-active-light-primary", }, // target: ".modal-dialog", ...attr, }; Swal.fire(config).then((result) => { if (callback) { callback(result); } }); }; const setLoadingButton = (elementSelector = null, status = false) => { let selector; try { selector = $(`${elementSelector}`); } catch (error) { selector = elementSelector; } if (status) { selector.attr("disabled", false); selector.attr("data-kt-indicator", "off"); selector.find("i").removeClass("d-none"); } else { selector.attr("disabled", true); selector.attr("data-kt-indicator", "on"); selector.find("i").addClass("d-none"); } }; const resetFormError = (elementSelector) => { let selector; try { selector = $(`${elementSelector}`); } catch (error) { selector = elementSelector; } $.each(selector.find("[data-field]"), (index, element) => { selector .find(`[name='${element.getAttribute("data-field")}']`) .removeClass("is-invalid"); element.innerHTML = ""; }); }; const setFormError = (elementSelector, errors = []) => { let selector; let errorKey; try { selector = $(`${elementSelector}`); } catch (error) { selector = elementSelector; } const field = selector.find("[data-field]"); $.each(field, (index, element) => { errorKey = element.getAttribute("data-field"); if (errors[errorKey]) { selector.find(`#${errorKey}`).addClass("is-invalid"); element.innerHTML = errors[errorKey]; } else { selector.find(`#${errorKey}`).removeClass("is-invalid"); element.innerHTML = ""; } errorKey = ""; }); }; const resetForm = (elementSelector, callback) => { let selector; try { selector = $(`${elementSelector}`); } catch (error) { selector = elementSelector; } selector.trigger("reset"); selector.find(`.image-input`).removeClass("image-input-changed"); selector.find(`.image-input`).addClass("image-input-empty"); selector.find(`.image-input .image-input-wrapper`).css({ "background-image": "none", }); selector.find(` select, input, textarea`).each(function () { let attrType = $(this).attr("type"); if (attrType === "radio" || attrType === "checkbox") { $(this).prop("checked", false); } else { $(this).val("").trigger("change"); $(this).val(""); } if (callback) callback(); }); resetFormError(elementSelector); }; const setDaterange = ( elementSelector, start, end, format = "D-MM-YYYY", callback = undefined ) => { let selector; try { selector = $(`${elementSelector}`); } catch (error) { selector = elementSelector; } function cb(start, end, title) { selector .find("#date") .html(`${start.format(format)} - ${end.format(format)}`); selector.find("#title").html(title); selector .find("input") .val(`${start.format(format)} - ${end.format(format)}`); if (callback) callback(); } selector.daterangepicker( { startDate: start, endDate: end, ranges: { Today: [moment(), moment()], Yesterday: [moment().subtract(1, "days"), moment().subtract(1, "days")], "Last 7 Days": [moment().subtract(6, "days"), moment()], "Last 30 Days": [moment().subtract(29, "days"), moment()], "This Month": [moment().startOf("month"), moment().endOf("month")], "Last Month": [ moment().subtract(1, "month").startOf("month"), moment().subtract(1, "month").endOf("month"), ], }, }, cb ); cb(start, end); }; const bootstrapTableConfig = () => { return { toolbar: "#toolbar", sidePagination: "server", queryParams: (params) => { $("[data-filter]").each(function () { params[$(this).attr("name")] = $(this).val(); }); return params; }, responseHandler: (res) => { res.rows = res?.rows.map((row, index) => { row.no = parseInt(res.from) + (index + 1); return row; }); return res; }, pagination: true, search: true, searchHighlight: true, singleSelect: false, striped: true, showColumns: false, showRefresh: false, showToggle: false, showFullscreen: false, showPaginationSwitch: false, pageSize: 5, pageList: [5, 10, 25, 50, "all"], iconSize: "sm", classes: "table align-middle table-row-dashed fs-6 gy-5 fw-semibold text-gray-600", buttonsClass: "primary btn-sm", loadingTemplate: () => `